﻿#include<iostream>
#include<assert.h>
using namespace std;
#define Elemtype char
#define MAX_SIZE 1000
/*
typedef struct SqStack
{
	Elemtype* base;
	int top;
	int capacity;
}Stack,*Sq;
void Init_Stack(Sq s)
{
	s->capacity = MAX_SIZE;
	s->top = 0;
	s->base = new Elemtype;
	assert(s->base);
	memset(s->base, 0, sizeof(s->base));
	/*for (int i = 0; i < s->capacity; i++)
	{
		s->base[i] = 0;
	}
}
bool Empty_Stack(Sq* s)
{
	if ((*s)->top == 0)
	{
		return true;
	}
	return false;
}
bool Empty_Stack(Sq s)
{
	if (s->top == 0)
	{
		return true;
	}
	return false;
}
bool Full_Stack(Sq* s)
{
	if ((*s)->capacity == (*s)->top)
	{
		return true;
	}
	return false;
}
void Push_Stack(Sq s, Elemtype ch)
{
	if (Empty_Stack(&s))
	{
		return;
	}
	s->top++;
	s->base[s->top] = ch;
}
void Pop_Stack(Sq s)
{
	if (Full_Stack(&s))
	{
		return;
	}
	s->top--;
}
void Get_Stack(Sq s, Elemtype* p)
{
	if (Empty_Stack(&s))
	{
		return;
	}
	s->top--;
	*p = s->base[s->top];
}*/
typedef struct
{
	char* base;
	int top;
	int capacity;
}SqStack, * Stack;
void Init_Stack(Stack s)
{
	s->base = (char*)malloc(sizeof(char) * MAX_SIZE);
	assert(s->base);
	s->capacity = MAX_SIZE;
	s->top = 0;
	for (int i = 0; i < s->capacity; i++)
	{
		s->base[i] = '0';
	}
}
bool Is_Full(Stack s)
{
	if (s->top >= s->capacity) {
		return true;
	}
	return false;
}
bool Is_Null(Stack s)
{
	if (s->top == 0) {
		return true;
	}
	return false;
}
void Push_Stack(Stack s, char x)
{
	if (Is_Full(s)) {
		return;
	}
	//ջ
	s->base[s->top] = x;
	s->top++;
}
void Pop_Stack(Stack s)
{
	if (Is_Null(s)) {
		return;
	}
	//ջ
	s->top--;
	//*x = s->base[s->top];
}
void Get_Stack(Stack s, char* x)
{
	if (Is_Null(s)) {
		return;
	}
	//ջ
	s->top--;
	*x = s->base[s->top];
}
bool Check(const char* p)
{
	SqStack my_stack;
	Init_Stack(&my_stack);
	char v;
	while (*p != '\0')
	{
		if (*p == '('||*p=='[')
		{
			Push_Stack(&my_stack,*p);
		}
		else if (*p == ')')
		{
			Get_Stack(&my_stack, &v);
			if (v != '(')
			{
				return false;
			}
			Pop_Stack(&my_stack);
		}
		else if (*p == ']')
		{
			Get_Stack(&my_stack, &v);
			if (v != '[')
			{
				return false;
			}
			Pop_Stack(&my_stack);
		}
		p++;
	}
	//return Empty_Stack(&my_stack);
	return Is_Null(&my_stack);
}
int main()
{
	char p[] = "((([(])))";
	bool ret = Check(p);
	if (ret)
	{
		cout << "True" << endl;
	}
	else
	{
		cout << "Error" << endl;
	}
	return 0;
}